package com.sinosoft.hydra.um.domain.permission;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.*;

import com.alibaba.fastjson.annotation.JSONField;
import com.sinosoft.hydra.um.constant.BaseConstant;
import cn.com.sinux.spring.utils.ValidatorUtils;;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

@Entity
@Table(name = "T_PROCESS_TEMPLATE")
public class TProcessTemplate implements Serializable {
    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column t_process_template.id
     *
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    @Size(max = 50, message = "tprocesstemplate.id.max.overflow")
    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    @Column(name = "ID")
    private String id;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column t_process_template.process_name
     *
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    @NotNull(message = "tprocesstemplate.processname.not.null")
    @Size(max = 100, message = "tprocesstemplate.processname.max.overflow")
    @Column(name = "PROCESS_NAME")
    private String processName;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column t_process_template.module
     *
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    @ManyToOne()
    @JoinColumn(name = "MODULE")
    @NotFound(action = NotFoundAction.IGNORE)
    private TDirectory module;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column t_process_template.create_user
     *
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    @NotNull(message = "tprocesstemplate.createuser.not.null")
    @Size(max = 50, message = "tprocesstemplate.createuser.max.overflow")
    @Column(name = "CREATE_USER")
    private String createUser;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column t_process_template.update_user
     *
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    @Size(max = 50, message = "tprocesstemplate.updateuser.max.overflow")
    @Column(name = "UPDATE_USER")
    private String updateUser;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column t_process_template.create_time
     *
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    @NotNull(message = "tprocesstemplate.createtime.not.null")
    @Column(name = "CREATE_TIME")
    @JSONField(format = "yyyy-MM-dd")
    private Date createTime;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column t_process_template.update_time
     *
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    @Column(name = "UPDATE_TIME")
    @JSONField(format = "yyyy-MM-dd")
    private Date updateTime;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column t_process_template.use_able
     *
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    @NotNull(message = "tprocesstemplate.useable.not.null")
    @Column(name = "USE_ABLE")
    private Integer useAble;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column t_process_template.remark
     *
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    @Size(max = 400, message = "tprocesstemplate.remark.max.overflow")
    @Column(name = "REMARK")
    private String remark;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column t_process_template.process_cover
     *
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    @NotNull(message = "tprocesstemplate.processcover.not.null")
    @Size(max = 200, message = "tprocesstemplate.processcover.max.overflow")
    @Column(name = "PROCESS_COVER")
    private String processCover;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column t_process_template.use_device
     *
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    @NotNull(message = "tprocesstemplate.usedevice.not.null")
    @Column(name = "USE_DEVICE")
    private Integer useDevice;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column t_process_template.device
     *
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    @OneToOne(cascade = CascadeType.DETACH)
    @JoinColumn(name = "DEVICE")
    @NotFound(action = NotFoundAction.IGNORE)
    private TDevice device;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database table t_process_template
     *
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    private static final long serialVersionUID = 1L;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column t_process_attribute.process_template
     *
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    @OneToMany
    @JoinColumn(name = "PROCESS_TEMPLATE", updatable = false, insertable = false)
    private List<TProcessAttribute> tProcessAttributes;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column t_process_record.process_template
     *
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    @JSONField(serialize = false)
    @OneToMany
    @JoinColumn(name = "PROCESS_TEMPLATE")
    private List<TProcessRecord> records;


    public boolean isSearchAble() {
        if (ValidatorUtils.isArrayNotEmpty(tProcessAttributes)) {
            for (TProcessAttribute processAttribute : tProcessAttributes) {
                if (BaseConstant.INTEGER_TRUE.equals(processAttribute.getSearchAble())) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column t_process_template.id
     *
     * @return the value of t_process_template.id
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public String getId() {
        return id;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column t_process_template.id
     *
     * @param id the value for t_process_template.id
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column t_process_template.process_name
     *
     * @return the value of t_process_template.process_name
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public String getProcessName() {
        return processName;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column t_process_template.process_name
     *
     * @param processName the value for t_process_template.process_name
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public void setProcessName(String processName) {
        this.processName = processName;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column t_process_template.module
     *
     * @return the value of t_process_template.module
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public TDirectory getModule() {
        return module;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column t_process_template.module
     *
     * @param module the value for t_process_template.module
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public void setModule(TDirectory module) {
        this.module = module;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column t_process_template.create_user
     *
     * @return the value of t_process_template.create_user
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public String getCreateUser() {
        return createUser;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column t_process_template.create_user
     *
     * @param createUser the value for t_process_template.create_user
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column t_process_template.update_user
     *
     * @return the value of t_process_template.update_user
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public String getUpdateUser() {
        return updateUser;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column t_process_template.update_user
     *
     * @param updateUser the value for t_process_template.update_user
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column t_process_template.create_time
     *
     * @return the value of t_process_template.create_time
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column t_process_template.create_time
     *
     * @param createTime the value for t_process_template.create_time
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column t_process_template.update_time
     *
     * @return the value of t_process_template.update_time
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public Date getUpdateTime() {
        return updateTime;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column t_process_template.update_time
     *
     * @param updateTime the value for t_process_template.update_time
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column t_process_template.use_able
     *
     * @return the value of t_process_template.use_able
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public Integer getUseAble() {
        return useAble;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column t_process_template.use_able
     *
     * @param useAble the value for t_process_template.use_able
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public void setUseAble(Integer useAble) {
        this.useAble = useAble;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column t_process_template.remark
     *
     * @return the value of t_process_template.remark
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public String getRemark() {
        return remark;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column t_process_template.remark
     *
     * @param remark the value for t_process_template.remark
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public void setRemark(String remark) {
        this.remark = remark;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column t_process_template.process_cover
     *
     * @return the value of t_process_template.process_cover
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public String getProcessCover() {
        return processCover;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column t_process_template.process_cover
     *
     * @param processCover the value for t_process_template.process_cover
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public void setProcessCover(String processCover) {
        this.processCover = processCover;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column t_process_template.use_device
     *
     * @return the value of t_process_template.use_device
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public Integer getUseDevice() {
        return useDevice;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column t_process_template.use_device
     *
     * @param useDevice the value for t_process_template.use_device
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public void setUseDevice(Integer useDevice) {
        this.useDevice = useDevice;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column t_process_template.device
     *
     * @return the value of t_process_template.device
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public TDevice getDevice() {
        return device;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column t_process_template.device
     *
     * @param device the value for t_process_template.device
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public void setDevice(TDevice device) {
        this.device = device;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table t_process_template
     *
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", processName=").append(processName);
        sb.append(", module=").append(module);
        sb.append(", createUser=").append(createUser);
        sb.append(", updateUser=").append(updateUser);
        sb.append(", createTime=").append(createTime);
        sb.append(", updateTime=").append(updateTime);
        sb.append(", useAble=").append(useAble);
        sb.append(", remark=").append(remark);
        sb.append(", processCover=").append(processCover);
        sb.append(", useDevice=").append(useDevice);
        sb.append(", device=").append(device);
        sb.append("]");
        return sb.toString();
    }

    public int getBestTotal() {
        int i = 0;
        if (ValidatorUtils.isArrayNotEmpty(records)) {
            for (TProcessRecord record : records) {
                if (BaseConstant.RecordType.RECORD_TYPE_BEST.name().equals(record.getType())) {
                    i++;
                }
            }
        }
        return i;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column t_process_attribute.process_template
     *
     * @return the value of t_process_attribute.process_template
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public List<TProcessAttribute> gettProcessAttributes() {
        return tProcessAttributes;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column t_process_attribute.process_template
     *
     * @param tProcessAttributes the value for t_process_attribute.process_template
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public void settProcessAttributes(List<TProcessAttribute> tProcessAttributes) {
        this.tProcessAttributes = tProcessAttributes;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column t_process_record.process_template
     *
     * @return the value of t_process_record.process_template
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public List<TProcessRecord> getRecords() {
        return records;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column t_process_record.process_template
     *
     * @param records the value for t_process_record.process_template
     * @mbggenerated Thu Jun 16 09:20:03 CST 2016
     */
    public void setRecords(List<TProcessRecord> records) {
        this.records = records;
    }
}